import type { RemoveMethods } from "@/types/remove-methods";

export class LifeModelData {
  id: number;
  name: string;
  desc: string;
  timeManageList: Array<number>;

  setInfo(data: RemoveMethods<LifeModelData>) {
    Object.assign(this, data);
  }
  constructor(id: number, name: string, desc: string, timeManageList: Array<number>) {
    this.id = id;
    this.name = name;
    this.desc = desc;
    this.timeManageList = timeManageList;
  }
}

export class LifeModel {
  chooseLifeModel: number; // 所选择的生活模式
  list: Array<number>;
  data: Array<LifeModelData>;

  setInfo(data: RemoveMethods<LifeModel>) {
    Object.assign(this, data);
  }

  constructor(chooseLifeModel: number, list: Array<number>, data: Array<LifeModelData>) {
    this.chooseLifeModel = chooseLifeModel;
    this.list = list;
    this.data = data;
  }
  getLifeModelDataById(id: number | undefined | null) {
    return this.data.find(value => value.id === id);
  }
  deleteTimeManageById(lifeModalDataId: number, timeManageId: number) {
    const lifeModelData: LifeModelData | undefined = this.getLifeModelDataById(lifeModalDataId);
    if (lifeModelData !== undefined)
      lifeModelData.timeManageList = lifeModelData.timeManageList.filter(item => item !== timeManageId);
  }
  getLifeModelSelectOptions() {
    return this.data.map(s => {
      return {
        label: s.name,
        value: s.id,
      };
    });
  }
}
